import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/a_yyt/models/floor_list_entity.dart';
import 'package:ls_work/config/global_configs.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/net/response/room_list_bea.dart';

import '../net/api/http_api.dart';

class BuildingModel extends BaseMvvmModel{
  @override
  void onCleared() {
  }


  ///楼栋列表
  Future<List<FloorEntity>> getBuildingList({int page = 1,int rows = 20,int? isFilter}) async {
    var map = {
      "page":page,
      "rows":rows,
      "isFilter":isFilter,
    };

    var url = GlobalConfigs.useArea?HttpApi.areaBuildingList:HttpApi.buildingList;

    var data = await HttpGo.instance.postData(url,data: map,options: PostRequest.urlencodedHeader);
    if(data['code'].toString()=='0'){
      FloorListEntity model = FloorListEntity.fromJson(data['data']);
      return model.rows??[];
    }else{
      throw data['msg'];
    }
  }


  ///楼层列表
  Future<void> getFloorList(String buildingId) async {
    var map  = {"buildingId":buildingId};
    var data = await HttpGo.instance.postData(HttpApi.floorList,data: map,options: PostRequest.urlencodedHeader);
    if(data['code'].toString()=='0'){

    }else{
      throw data['msg'];
    }

  }

  Future<List<RoomListBean>> getRoomList({String floorId = "",String building = "",int page = 1,int rows = 20}) async {
    var map = {
      "floor":floorId,
      "buildingId":building,
      "page":page,
      "rows":rows,
    };
    var data = await HttpGo.instance.postData(HttpApi.roomList,data: map,);

    if(data['code'].toString()=='0'){
      var list = ((data['data']['rows'] as List?)??[]).map((e) => RoomListBean.fromJson(e)).toList();
      return list;
    }else{
      throw data['msg'];
    }
  }

}